home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 22 / Amiga Format AFCD22 (Jan 1998, Issue 106).iso / -in_the_mag- / converters / graphics / netpbm / hpcdtoppm.0.6 / src / pcdindex < prev    next >
Text File  |  1997-11-16  |  5KB  |  206 lines

  1. #!/bin/csh -f
  2. #
  3. # pcdindex - generate a single PPM file from a PCD overview file
  4. #
  5. # This script assumes that the PBMPLUS and hpcdtoppm software
  6. # packages are installed, and that /tmp has enough space
  7. # (worst case 150Kbyte per image).
  8. # Based on pnmindex (PBMPLUS), which was written by Jef Poskanzer,
  9. # this script makes also use of hpcdtoppm, written by Hadmut Danisch.
  10. #
  11. # A similar result can be achieved by using "hpcdtoppm -Overview"
  12. # followed by "pnmindex -black" on the generated PPM images.
  13. # This shell just makes it more convenient and transparent to
  14. # convert from one PCD to one PPM overview file.
  15. #
  16. # Additional options (compared to pnmindex) are -maxwidth and
  17. # -font <font>. See "man pbmtext" on how to create your own font.
  18. #
  19. # Pieter S. van der Meulen, 1992.
  20.  
  21. # You may want to change the default values in the next 6 lines:
  22. set maxwidth=1152    # maximum width of the index image
  23. set size=192        # make the images about this big
  24. set across=6        # show this many images per row
  25. set colors="noquant"    # maximum amount of colors or noquant (no quantization)
  26. set back="-black"    # default background color
  27. set font=" "        # default font or none (pbmtext's internal font)
  28.  
  29. # Parse the options
  30. while ( 1 )
  31.     switch ( "$1" )
  32.  
  33.     case -m*:
  34.     if ( $#argv < 2 ) goto usage
  35.     set maxwidth="$2"
  36.     shift
  37.     shift
  38.     breaksw
  39.  
  40.     case -s*:
  41.     if ( $#argv < 2 ) goto usage
  42.     set size="$2"
  43.     shift
  44.     shift
  45.     breaksw
  46.  
  47.     case -a*:
  48.     if ( $#argv < 2 ) goto usage
  49.     set across="$2"
  50.     shift
  51.     shift
  52.     breaksw
  53.  
  54.     case -c*:
  55.     set colors="$2"
  56.     shift
  57.     shift
  58.     breaksw
  59.  
  60.     case -f*:
  61.     set font="-font $2"
  62.     shift
  63.     shift
  64.     breaksw
  65.  
  66.     case -b*:
  67.     set back="-black"
  68.     shift
  69.     breaksw
  70.  
  71.     case -w*:
  72.     set back="-white"
  73.     shift
  74.     breaksw
  75.  
  76.     case -*:
  77.     echo "$0 : Unknown option $1"
  78.     echo " "
  79.     goto usage
  80.     breaksw
  81.  
  82.     default:
  83.     break
  84.     breaksw
  85.  
  86.     endsw
  87. end
  88.  
  89. if ( $#argv == 0 ) then
  90.     goto usage
  91. endif
  92.  
  93. set tmpfile=/tmp/pi.tmp.$$
  94. rm -f $tmpfile
  95. touch /tmp/img0001 # Avoid complaints about non matching
  96. rm -f /tmp/img*
  97.  
  98. set rowfiles=()
  99. set imagefiles=()
  100. @ row = 1
  101. @ col = 1
  102. @ width = $size
  103.  
  104. # Convert the PCD overview file to many PPM images
  105. if (-f $1) then
  106.     hpcdtoppm -Overview $1 /tmp/img
  107. else
  108.     echo "$0 : Could not access $1"
  109.     echo " "
  110.     goto usage
  111. endif
  112.  
  113. foreach i ( /tmp/img* )
  114.  
  115. if (-f $i) then
  116.     set description=`pnmfile $i`
  117.     if ( $description[4] <= $size && $description[6] <= $size ) then
  118.     cat $i > $tmpfile
  119.     else
  120.         if ( $colors =~ n* ) then
  121.         pnmscale -quiet -xysize $size $size $i > $tmpfile
  122.         else
  123.         pnmscale -quiet -xysize $size $size $i | ppmquant -quiet $colors > $tmpfile
  124.         endif
  125.     endif
  126.     set imagefile=/tmp/pi.${row}.${col}.$$
  127.     rm -f $imagefile
  128.     set ttext=$i:t
  129.     if ( "$back" == "-white" ) then
  130.     pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2| pnmcat $back -tb $tmpfile - > $imagefile
  131.     else
  132.     pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2 | pnminvert | pnmcat $back -tb $tmpfile - > $imagefile
  133.     endif
  134.     rm -f $tmpfile
  135.     set description=`pnmfile $imagefile`
  136.     @ width += $description[4]
  137.     set imagefiles=( $imagefiles $imagefile )
  138.  
  139.     if (( $col >= $across ) || ( $width > $maxwidth)) then
  140.     set rowfile=/tmp/pi.${row}.$$
  141.     rm -f $rowfile
  142.     if ( $colors =~ n* ) then
  143.         pnmcat $back -lr -jbottom $imagefiles > $rowfile
  144.     else
  145.         pnmcat $back -lr -jbottom $imagefiles | ppmquant -quiet $colors > $rowfile
  146.     endif
  147.     rm -f $imagefiles
  148.     set imagefiles=()
  149.     set rowfiles=( $rowfiles $rowfile )
  150.     @ col = 1
  151.     @ row += 1
  152.     @ width = $size
  153.     else
  154.     @ col += 1
  155.     endif
  156. endif
  157.  
  158. end
  159.  
  160. if ( $#imagefiles > 0 ) then
  161.     set rowfile=/tmp/pi.${row}.$$
  162.     rm -f $rowfile
  163.     if ( $colors =~ n* ) then
  164.     pnmcat $back -lr -jbottom $imagefiles > $rowfile
  165.     else
  166.     pnmcat $back -lr -jbottom $imagefiles | ppmquant -quiet $colors > $rowfile
  167.     endif
  168.     rm -f $imagefiles
  169.     set rowfiles=( $rowfiles $rowfile )
  170. endif
  171.  
  172. if ( $#rowfiles == 1 ) then
  173.     cat $rowfiles
  174. else
  175.     if ( $colors =~ n* ) then
  176.     pnmcat $back -tb $rowfiles
  177.     else
  178.     pnmcat $back -tb $rowfiles | ppmquant -quiet $colors
  179.     endif
  180. endif
  181. rm -f $rowfiles
  182. rm -f /tmp/img*
  183.  
  184. exit 0
  185.  
  186. usage:
  187.     echo "Usage: $0 [-m W] [-s S] [-a A] [-c N|n] [-f F] [-b|-w] <overview.pcd>"
  188.     echo " with"
  189.     echo "    W = maximum width of the result image    (default: $maxwidth)"
  190.     echo "    S = maximum size of each of the images    (default: $size)"
  191.     echo "    A = maximum number of images across    (default: $across)"
  192.     echo "    N = maximum number of colors or noquant    (default: $colors)"
  193.     echo -n "    F = font to be used for annotation      (default: "
  194.     if ( "$font" == " " ) then
  195.     echo "internal font)"
  196.     else
  197.     echo "$font)"
  198.     endif
  199.     echo "    -b/-w = black/white background color    (default: $back)"
  200.     echo " "
  201.     echo " e.g.: $0 -m 768 -s 96 -f smallfont.pbm overview.pcd > overview.ppm"
  202.     echo " or  : $0 /cdrom/photo_cd/overview.pcd | cjpeg > overview.jpg"
  203. exit 1
  204.  
  205.  
  206.